package edu.cuit.avatar.concurrent;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 线程安全的集合类
 * Vector ---> Stack
 * ConcurrentXxx
 * -------------------------------------------------------------------------
 * ConcurrentHashMap:
 *      1. jdk8以前采用的是分段锁;
 *      2. jdk8以后采用CAS(乐观锁) + synchronized 进一步提升性能
 * HashTable:不推荐使用,效率较低;推荐使用ConcurrentHashMap
 * 使用Collections中对应的6个静态方法将集合转换为同步版本
 * ---------------------写时复制:读多写很少的同步情况--------------------------
 * CopyOnWriteArrayList
 * CopyOnWriteSet
 * ------------------------------------------------------------------------
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/17 15:32
 */
public class SynchronizedCollectionTest {
    private static List<String> names = new ArrayList<>();
    //private static CopyOnWriteArrayList list
    public static void main(String[] args) {
        List<String> list = Collections.synchronizedList(names);
    }
}
